package com.example.vaccine.controller;

import com.example.vaccine.VO.ResultVO;
import com.example.vaccine.service.StatisticsService;
import com.example.vaccine.util.ResultVOUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/statistics")
@Tag(name = "统计接口", description = "疫苗及核查任务统计相关接口")
public class StatisticsController {

    @Autowired
    private StatisticsService statisticsService;

    @Operation(summary = "疫苗库存 & 接种总览", description = "返回指定时间范围内的疫苗库存和接种总览数据")
    @GetMapping("/vaccine-overview")
    public ResultVO<Map<String, Integer>> vaccineOverview(
            @Parameter(name = "timeRange", description = "时间范围，支持如7days, 30days，默认7days", required = false, in = ParameterIn.QUERY)
            @RequestParam(defaultValue = "7days") String timeRange) {
        Map<String, Integer> data = statisticsService.getVaccineOverview(timeRange);
        return ResultVOUtil.success(data);
    }

    @Operation(summary = "核查任务状态分布", description = "返回指定时间范围内核查任务的状态分布")
    @GetMapping("/checktask-status")
    public ResultVO<Map<String, Integer>> checkTaskStatus(
            @Parameter(name = "timeRange", description = "时间范围，支持如7days, 30days，默认7days", required = false, in = ParameterIn.QUERY)
            @RequestParam(defaultValue = "7days") String timeRange) {
        Map<String, Integer> data = statisticsService.getCheckTaskStatus(timeRange);
        return ResultVOUtil.success(data);
    }

    @Operation(summary = "疫苗接种量排行", description = "返回指定时间范围内按疫苗名称统计的接种量排行")
    @GetMapping("/vaccine-usage-ranking")
    public ResultVO<List<Map<String, Object>>> vaccineUsageRanking(
            @Parameter(name = "timeRange", description = "时间范围，支持如7days, 30days，默认7days", required = false, in = ParameterIn.QUERY)
            @RequestParam(defaultValue = "7days") String timeRange) {
        List<Map<String, Object>> data = statisticsService.getVaccineUsageRanking(timeRange);
        return ResultVOUtil.success(data);
    }
}
